package org.example.netty.httpserver.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * 字节转换成json
 */
public class ByteToJSON extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        byte[] content = new byte[in.readableBytes()];
        in.readBytes(content);
        out.add(new String(content));
    }
}
